# 编译器和选项
CC      := g++
CFLAGS  := -std=c++14 
DEBUG   := -g 
INCLUDE := -I/home/timer/gtest/build/_install/include \
           -I./

ThirdPartyLibPath := -L/home/timer/gtest/build/_install/lib

ThirdPartyLib := -lrt -latomic -lpthread -lgtest 

# 可执行文件列表
EXECUTABLES := test_croutine test_scheduler


# 找出源文件
SRCS := $(shell find ./* -type f | grep '\.cpp' | grep -v './test.*\.cpp')
ASMS := $(shell find ./* -type f | grep '\.S')
OBJS := $(patsubst %.cpp, %.o, $(SRCS)) $(patsubst %.S, %.o, $(ASMS))

# 编译规则
%.o: %.cpp
	$(CC) $(INCLUDE) $(CFLAGS) $(DEBUG) -c -o $@ $<

%.o: %.S
	$(AS) -c $< -o $@

# 生成可执行文件的规则
$(EXECUTABLES): %: $(OBJS) %.cpp
	$(CC) $(INCLUDE) $(DEBUG) -o $@.out $^ $(ThirdPartyLibPath) $(ThirdPartyLib)

# 清理规则
.PHONY: clean
clean:
	rm -rf *.out *.log $(OBJS)